package com.ruoyi.tb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tb.domain.AdminTb;
import com.ruoyi.tb.service.IAdminTbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管理员表Controller
 * 
 * @author ruoyi
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/tb/tb")
public class AdminTbController extends BaseController
{
    @Autowired
    private IAdminTbService adminTbService;

    /**
     * 查询管理员表列表
     */
    @PreAuthorize("@ss.hasPermi('tb:tb:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdminTb adminTb)
    {
        startPage();
        List<AdminTb> list = adminTbService.selectAdminTbList(adminTb);
        return getDataTable(list);
    }

    /**
     * 导出管理员表列表
     */
    @PreAuthorize("@ss.hasPermi('tb:tb:export')")
    @Log(title = "管理员表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdminTb adminTb)
    {
        List<AdminTb> list = adminTbService.selectAdminTbList(adminTb);
        ExcelUtil<AdminTb> util = new ExcelUtil<AdminTb>(AdminTb.class);
        util.exportExcel(response, list, "管理员表数据");
    }

    /**
     * 获取管理员表详细信息
     */
    @PreAuthorize("@ss.hasPermi('tb:tb:query')")
    @GetMapping(value = "/{AdminId}")
    public AjaxResult getInfo(@PathVariable("AdminId") Long AdminId)
    {
        return success(adminTbService.selectAdminTbByAdminId(AdminId));
    }

    /**
     * 新增管理员表
     */
    @PreAuthorize("@ss.hasPermi('tb:tb:add')")
    @Log(title = "管理员表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdminTb adminTb)
    {
        return toAjax(adminTbService.insertAdminTb(adminTb));
    }

    /**
     * 修改管理员表
     */
    @PreAuthorize("@ss.hasPermi('tb:tb:edit')")
    @Log(title = "管理员表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdminTb adminTb)
    {
        return toAjax(adminTbService.updateAdminTb(adminTb));
    }

    /**
     * 删除管理员表
     */
    @PreAuthorize("@ss.hasPermi('tb:tb:remove')")
    @Log(title = "管理员表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{AdminIds}")
    public AjaxResult remove(@PathVariable Long[] AdminIds)
    {
        return toAjax(adminTbService.deleteAdminTbByAdminIds(AdminIds));
    }
}
